﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using RedPanda.MusicPlayer.ViewModel;
using RedPanda.MusicPlayer.DataModel;

using RedPanda.MusicPlayer;

namespace RedPanda.Controls.MusicPlayer
{
    /// <summary>
    /// PlaybackControl.xaml 的交互逻辑
    /// </summary>
    public partial class PlaybackControl : UserControl
    {
        #region field
        private AudioFileViewModel currentTrack = App.mainViewModel.CurrentTrack;
        private PlaylistViewModel currentPlaylist = App.mainViewModel.CurrentPlaylist;

        private MPlayer mplayer;
        private bool isPlaying = false;

        #endregion 
        public PlaybackControl()
        {
            mplayer = new MPlayer();
            InitializeComponent();
            this.DataContext = currentTrack;
        }

        /// <summary>
        /// 播放前一首歌
        /// 从当前的Playlist中获得下一首歌并且播放;
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void previousButton_Click(object sender, RoutedEventArgs e)
        {
            mplayer.PlayPreviousTrack();
        }

        private void playButton_Click(object sender, RoutedEventArgs e)
        {
            if (!isPlaying)
            {
                mplayer.StartPlayback();
            }
            else
            {
                mplayer.PausePlayback();
               
            }
        }

        private void nextButton_Click(object sender, RoutedEventArgs e)
        {
            mplayer.PlayNextTrack();
        }

        private void stopButton_Click(object sender, RoutedEventArgs e)
        {
            mplayer.StopPlayback();
        }

        private void volumeSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {

        }

        private void durationSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {

        }
    }
}
